package com.wyc.controller;

import com.wyc.pojo.Emp;
import com.wyc.pojo.PageBean;
import com.wyc.pojo.Result;
import com.wyc.service.EmpsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Lazy
@RestController
@RequestMapping("/emps")
public class EmpsController {
    @Autowired
    private EmpsService empsService;

    //分页查询
    @GetMapping
    public Result page(@RequestParam(defaultValue = "1" ) Integer pageindex,
                       @RequestParam(defaultValue = "3" ) Integer pagesize){
        PageBean<Emp> page = empsService.page(pageindex, pagesize);

        return Result.success(page);
    }

    //删除员工 根据id

    @DeleteMapping("/{ids}")
    public  Result delByIds(@PathVariable List<Integer> ids){
        empsService.delByIds(ids);
        return Result.success();
    }





    //新增员工
    @PostMapping
    public Result save(@RequestBody Emp emp){
        empsService.save(emp);
        return Result.success();
    }

    //根据id查询
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){

         return Result.success(empsService.getById(id));

    }

    //更新员工
    @PutMapping
    public Result update(@RequestBody Emp emp){
        empsService.update(emp);
        return Result.success();
    }
}
